<template>
  <el-dialog
    title="修改订单地址"
    :visible.sync="dialogVisibleEdit"
    :before-close="closedDialog"
  >
    <el-form v-if="orderInfoForm" :model="orderInfoForm" label-position="top">
      <el-form-item label="省市区">
        <!--级联选择器的使用  -->
        <el-cascader
          :options="cityOptions"
          v-model="form.cascaderSelected"
          @change="handleCategoryChange"
          :props="cascaderProps"
          clearable
        ></el-cascader>
      </el-form-item>
      <el-form-item label="详细地址" label-width="120px">
        <el-input v-model="orderInfoForm.username"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="closedDialog">取 消</el-button>
      <el-button type="primary" @click="submitDialog">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import cityOptions from '@/plugins/city_data2017_element'
export default {
  props: {
    dialogVisibleEdit: {
      type: Boolean,
      default: false,
    },
    orderInfo: {
      type: Object,
      default() {
        return {}
      },
    },
  },
  data() {
    return {
      form: {
        categoryName: '',
        cascaderSelected: [],
      },
      cityOptions: cityOptions,
      cascaderProps: {
        value: 'value',
        label: 'label',
        // checkStrictly: true,
        expandTrigger: 'hover',
      },
    }
  },
  computed: {
    orderInfoForm() {
      return this.orderInfo
    },
  },
  methods: {
    handleCategoryChange(options) {
      // console.log(options)
    },
    closedDialog() {
      this.$parent.$data.dialogVisibleEdit = false
    },
    async submitDialog() {
      const { id, email, mobile } = this.orderInfoForm
      console.log(email, mobile)

      const {
        data: { meta },
      } = await this.$http.put('users/' + id, {
        email,
        mobile,
      })

      if (meta.status === 200) {
        // 添加成功后，关闭对话框，更新 users 页码表格数据
        this.$message.success(meta.msg)
        this.$parent.$data.dialogVisibleEdit = false
        this.$emit('editSuccess')
      } else {
        this.$message.error(meta.msg)
      }
    },

    testfun() {
      this.closedDialog()
    },
  },
}
</script>

<style></style>
